import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { timeInterval } from './dict';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Select',
    fieldName: 'timeInterval',
    label: '时间区间',
    componentProps: {
      fieldNames: { label: 'label', value: 'value' },
      options: timeInterval,
    },
  },
  {
    component: 'RangePicker',
    fieldName: 'timeIntervalRange',
    label: '选择区间',
    componentProps: {
      format: 'YYYY-MM-DD HH:mm:ss',
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      fieldNames: { label: 'label', value: 'value' },
      options: timeInterval,
    },
    dependencies: {
      if(values) {
        return values.timeInterval === 0;
      },
      // 只有指定的字段改变时，才会触发
      triggerFields: ['timeInterval'],
    },
  },
];

export const columns: VxeGridProps['columns'] = [
  {
    field: 'ts',
    title: '上报时间',
  },
  {
    field: 'customervalue',
    slots: { default: 'customervalue' },
    title: '属性值',
  },
];
